package io.renren.modules.project.controller;

import java.util.List;
import java.util.Map;

import io.renren.common.annotation.SysLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.project.entity.PrjectMessageEntity;
import io.renren.modules.project.service.PrjectMessageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-11-22 17:13:01
 */
@RestController
@RequestMapping("/generator/prjectmessage")
public class PrjectMessageController {
	@Autowired
	private PrjectMessageService prjectMessageService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("generator:prjectmessage:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<PrjectMessageEntity> prjectMessageList = prjectMessageService.queryList(query);
		int total = prjectMessageService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(prjectMessageList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("generator:prjectmessage:info")
	public R info(@PathVariable("id") String id){
		PrjectMessageEntity prjectMessage = prjectMessageService.queryObject(id);
		
		return R.ok().put("prjectMessage", prjectMessage);
	}

	/**
	 * 根据项目id查询消息
	 */
	@RequestMapping("/queryProjectId/{projectId}")
	public R queryProjectId(@PathVariable("projectId") String projectId){
        List<PrjectMessageEntity> prjectMessageList = prjectMessageService.queryProjectId(projectId);
		return R.ok().put("prjectMessage", prjectMessageList);
	}

	/**
	 * 根据用户id查询消息
	 */
	@RequestMapping("/queryUserMessage/{userId}")
	public R queryUserMessage(@PathVariable("userId") String userId){
		List<PrjectMessageEntity> prjectMessageList = prjectMessageService.queryUserMessage(userId);
		return R.ok().put("prjectMessage", prjectMessageList);
	}
	
	/**
	 * 保存
	 */
	@SysLog("新增消息")
	@RequestMapping("/save")
	public R save(@RequestBody PrjectMessageEntity prjectMessage){
		prjectMessageService.save(prjectMessage);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("generator:prjectmessage:update")
	public R update(@RequestBody PrjectMessageEntity prjectMessage){
		prjectMessageService.update(prjectMessage);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("generator:prjectmessage:delete")
	public R delete(@RequestBody String[] ids){
		prjectMessageService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
